<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="generator" content=
"HTML Tidy for Windows (vers 14 February 2006), see www.w3.org" />
<title>Reconditioned Machines</title>
<link rel="stylesheet" href="home.css" type="text/css" />
<?php include 'menu.php'; include 'imgresize.php' ?>
</head>
<body>
<?
//print_r($_POST);

if($_POST["action"] == "Upload Image")
{
	unset($imagename);
	if(!isset($_FILES) && isset($HTTP_POST_FILES))
		$_FILES = $HTTP_POST_FILES;
	if(!isset($_FILES['image_file']))
		$error["image_file"] = "An image was not found.";
	$imagename = basename($_FILES['image_file']['name']);
	//echo $imagename;
	if(empty($imagename))
		$error["imagename"] = "The name of the image was not found.";

	if(empty($error))
	{
		$newimage = "pictures/test/temp-import-pic.jpg";
		//echo $newimage;
		$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
		if(empty($result))
			$error["result"] = "There was an error moving the uploaded file.";

		$cowtag = ereg_replace("[^A-Za-z0-9]", "", $_POST["cowtag"]);

		$thumbfile = "pictures/test/" . $cowtag . "thumb.jpg";
		$thumb=new thumbnail($newimage);
		$thumb->size_height(60);
		$thumb->save($thumbfile);
		echo("<img src='$thumbfile'>");

		$zoomfile = "pictures/test/" . $cowtag . ".jpg";
		$zoom=new thumbnail($newimage);
		$zoom->size_auto(508);
		$zoom->save($zoomfile);
		echo("<img src='$zoomfile'>");

		unlink($newimage);

	}

}

?>


<form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?$_SERVER["PHP_SELF"];?>">
<p><input type="text" name="cowtag"></p>
<p><input type="file" name="image_file" size="20"></p>
<p><input type="submit" value="Upload Image" name="action"></p>
</form>

<?
if(is_array($error))
{
while(list($key, $val) = each($error))
{
echo $val;
echo "<br>\n";
}
}
?>

</body>
</html>
